package com.kaishengit.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;


import com.kaishengit.dao.ContactDao;
import com.kaishengit.dao.DealContactDao;
import com.kaishengit.dao.DealDao;
import com.kaishengit.pojo.Contact;
import com.kaishengit.pojo.Deal;
import com.kaishengit.pojo.DealContact;
@Transactional
public class DealContactService {
	private DealContactDao dealContactDao;
	private DealDao dealDao;
	private ContactDao contactDao;
	public Contact save(String dealid, String contactid) {
		Deal deal = dealDao.findByUnique("id",dealid);
		Contact contact = contactDao.findByUnique("id",contactid);
		DealContact dealContact = new DealContact();
		dealContact.setContact(contact);
		dealContact.setDeal(deal);
		dealContact.setRole("member");
		dealContactDao.save(dealContact);
		return contact;
		
	}
	//set
	public void setDealContactDao(DealContactDao dealContactDao) {
		this.dealContactDao = dealContactDao;
	}
	public void setDealDao(DealDao dealDao) {
		this.dealDao = dealDao;
	}
	public void setContactDao(ContactDao contactDao) {
		this.contactDao = contactDao;
	}
	/*public List<DealContact> findByDeal(Deal deal) {
		 List<DealContact> list= dealContactDao.findAllByProperty("deal",deal);
		 return list;
		
	}*/
	public void del(String contactid, String dealid) {
		Contact contact = contactDao.findByUnique("id",contactid);
		System.out.println(contact.getName());
		Deal deal = dealDao.findByUnique("id", dealid);
		System.out.println(deal.getContactname());
		String hql = "from DealContact where contact=:contact and deal =:deal";
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("contact",contact);
		map.put("deal",deal);
		DealContact dc= dealContactDao.findUnique(hql,map);
		dealContactDao.del(dc.getId());
		
	}
	


	
}
